<!--  -->
<template>
  <div>
    <el-card style="margin: 20px 0">
      <CategorySelect @getCategoryId="getCategoryId" />
    </el-card>
    <el-card>
      <!-- 展示属性 -->
      <div v-show="isShowTable">
        <el-button
          @click="isShowTable = false"
          style="margin: 0 0 10px 0"
          :disabled="!category3Id"
          type="primary"
          >添加属性</el-button
        >
        <el-table border :data="attrList" style="width: 100%">
          <el-table-column
            header-align="center"
            align="center"
            prop="prop"
            label="序号"
            width="80"
            type="index"
          >
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="attrName"
            label="属性名称"
            width="150"
          >
          </el-table-column>
          <el-table-column header-align="center" prop="prop" label="属性值列表">
            <template slot-scope="{ row }">
              <el-tag
                style="margin: 5px 8px"
                type="success"
                v-for="item in row.attrValueList"
                :key="item.id"
                >{{ item.valueName }}</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="prop"
            label="操作"
            width="150"
          >
            <template>
              <el-button
                style="margin: 0 8px"
                type="warning"
                icon="el-icon-edit"
                size="mini"
                @click="isShowTable = false"
              ></el-button>
              <el-button
                style="margin: 0 8px"
                type="danger"
                icon="el-icon-delete"
                size="mini"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 添加修改属性 -->
      <div v-show="!isShowTable">
        <el-form ref="form" :inline="true" label-width="80px">
          <el-form-item label="属性名">
            <el-input placeholder="请输入属性名"></el-input>
          </el-form-item>
        </el-form>
        <el-button type="primary" icon="el-icon-plus">添加属性值</el-button>
        <el-button @click="isShowTable=true">取消</el-button>
        <el-table border style="width: 100%;margin:20px 0">
          <el-table-column align="center" label="序号" type="index" width="80">
          </el-table-column>
          <el-table-column label="属性值名称" width="width"> </el-table-column>
          <el-table-column label="操作" width="width"> </el-table-column>
        </el-table>
        <el-button type="primary">保存</el-button>
        <el-button @click="isShowTable=true">取消</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Attr",
  data() {
    return {
      category1Id: "",
      category2Id: "",
      category3Id: "",
      //平台属性数据
      attrList: [],
      isShowTable: false,
    };
  },
  methods: {
    //自定义回复事件的回调
    getCategoryId({ categoryId, level }) {
      if (level == 1) {
        this.category1Id = categoryId;
        this.category2Id = "";
        this.category3Id = "";
      } else if (level == 2) {
        this.category2Id = categoryId;
        this.category3Id = "";
      } else {
        this.category3Id = categoryId;
        //获取平台属性数组
        this.getAttrList();
      }
    },
    //发送请求数据
    async getAttrList() {
      const { category1Id, category2Id, category3Id } = this;
      let res = await this.$API.attr.reqAttrList(
        category1Id,
        category2Id,
        category3Id
      );
      // console.log(res);
      if (res.code == 200) {
        this.attrList = res.data;
      }
    },
  },
};
</script>

<style scoped>
</style>
